package com.controller;

import com.common.constant.ResultCodeConstant;
import com.common.response.RestResult;
import com.model.dos.CompetitionDO;
import com.model.dto.CompetitionDTO;
import com.model.query.CompetitionQuery;
import com.service.CompetitionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *   比赛管理Controller
 * </p>
 * @author 34448
 */
@Api("比赛管理")
@RequestMapping("competition")
@RestController
public class CompetitionController {

    @Autowired
    private CompetitionService competitionService;

    /**
     * 创建比赛
     *
     * @param competitionDTO 比赛信息
     * @return 是否创建成功
     */
    @PostMapping("/add")
    @ApiOperation("创建比赛")
    public RestResult<Boolean> addCompetition(@Valid @RequestBody CompetitionDTO competitionDTO) {
        Boolean result = competitionService.addCompetition(competitionDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 修改比赛
     *
     * @param competitionDTO 比赛信息
     * @return 是否修改成功
     */
    @PutMapping("/update")
    @ApiOperation("修改比赛")
    public RestResult<Boolean> updateCompetition(@Valid @RequestBody CompetitionDTO competitionDTO) {
        Boolean result = competitionService.updateCompetition(competitionDTO);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 删除比赛
     *
     * @param competitionId 比赛ID
     * @return 是否删除成功
     */
    @DeleteMapping("/delete/{competitionId}")
    @ApiOperation("删除比赛")
    public RestResult<Boolean> deleteCompetition(@PathVariable Integer competitionId) {
        Boolean result = competitionService.deleteCompetition(competitionId);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 查询比赛
     *
     * @param competitionQuery 查询条件
     * @return 比赛信息列表
     */
    @GetMapping("/query")
    @ApiOperation("查询比赛")
    public RestResult<List<CompetitionDO>> queryCompetitions(@Validated CompetitionQuery competitionQuery) {
        List<CompetitionDO> result = competitionService.queryCompetitions(competitionQuery);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 导入比赛信息
     *
     * @param filePath 文件路径
     * @return 是否导入成功
     */
    @PostMapping("/import")
    @ApiOperation("导入比赛信息")
    public RestResult<Boolean> importCompetitions(@RequestParam String filePath) {
        Boolean result = competitionService.importCompetitions(filePath);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }

    /**
     * 导出比赛信息
     *
     * @param filePath 文件路径
     * @return 是否导出成功
     */
    @PostMapping("/export")
    @ApiOperation("导出比赛信息")
    public RestResult<Boolean> exportCompetitions(@RequestParam String filePath) {
        Boolean result = competitionService.exportCompetitions(filePath);
        return new RestResult<>(ResultCodeConstant.CODE_000000, ResultCodeConstant.CODE_000000_MSG, result);
    }
}